package diamondRingServlet;

import diamondRingEntity.Address;
import diamondRingEntity.Order;
import diamondRingService.impl.AddressServiceImpl;
import diamondRingService.impl.DiamondRingServiceImpl;
import diamondRingService.impl.OrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

//订单新增信息
@WebServlet("/OrderInsertServlet")
public class OrderInsertServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        response.setCharacterEncoding("utf-8");
        OrderServiceImpl bo=new OrderServiceImpl();
        AddressServiceImpl bo2=new AddressServiceImpl();
        PrintWriter out=response.getWriter();
        List<Address> list=bo2.addFind(Integer.parseInt(request.getParameter("userid")));
        Order order=new Order(list.get(0).getAddressId(), Integer.parseInt(request.getParameter("userid")),request.getParameter("orderNumber"),request.getParameter("purchaseTime"),Integer.parseInt(request.getParameter("transactionPrice")),Integer.parseInt(request.getParameter("shoppingNum")),request.getParameter("remarks"));
        int count=bo.orderInsert(order);
        out.print(count);
        out.flush();
        out.close();

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request,response);
    }
}
